package com.n5x.model.shopping;

import com.n5x.model.AbstractModel;

import java.util.Date;

/**
 * 订单物流
 */
public class ShoppingOrderLogistics extends AbstractModel {

    private ShoppingOrderLogistics() {
    }

    public ShoppingOrderLogistics(LogisticsState state, String fkShoppingOrderId) {
        this.state = state.name();
        this.fkShoppingOrderId = fkShoppingOrderId;
    }

    public enum LogisticsState {
        下单, 付款, 发货, 取货, 交易完成,取消订单, 申请换货, 申请退货, 商品回收, 重新发货, 退回货款, 取消订单成功, 取消订单失败, 退换货成功, 退换货失败, 交易作废;

        public static LogisticsState getShoppingOrderType(Integer ordinal) {
            if (ordinal == null) return null;
            int size = LogisticsState.values().length;
            if (ordinal < 0 || ordinal > size - 1) return null;
            return LogisticsState.values()[ordinal];
        }


        public static String[] FINISH_LOGISTICS_STATES() {
            return new String[]{LogisticsState.交易完成.name(), LogisticsState.交易作废.name()};
        }

        public static String[] getNextStates(String state) {
            if (state.equals(LogisticsState.付款.name())) {
                return new String[]{LogisticsState.发货.name(), LogisticsState.取消订单.name()};
            }
            if (state.equals(LogisticsState.发货.name())) {
                return new String[]{LogisticsState.取货.name(), LogisticsState.交易完成.name(),LogisticsState.取消订单.name()};
            }
            if (state.equals(LogisticsState.取货.name())) {
                return new String[]{LogisticsState.交易完成.name(), LogisticsState.申请换货.name(), LogisticsState.申请退货.name()};
            }
            if (state.equals(LogisticsState.取消订单成功.name()) || state.equals(LogisticsState.退换货成功.name())) {
                return new String[]{LogisticsState.交易作废.name()};
            }
            return null;
        }
    }

    public ShoppingOrderLogistics settingTransaction(String fkUserTransactionId, byte[] remarks) {
        this.fkUserTransactionId = fkUserTransactionId;
        this.remarks = remarks;
        return this;
    }

    /**
     * 关联订单ID
     */
    private String fkShoppingOrderId;

    /**
     * 关联用户交易记录
     */
    private String fkUserTransactionId;

    /**
     * 状态
     */
    private String state;

    /**
     * 物流时间
     */
    private Date logisticsTime = new Date();

    /**
     * 备注
     */
    private byte[] remarks;

    public String getFkShoppingOrderId() {
        return fkShoppingOrderId;
    }

    public void setFkShoppingOrderId(String fkShoppingOrderId) {
        this.fkShoppingOrderId = fkShoppingOrderId;
    }

    public String getState() {
        return state;
    }

    public void setState(String state) {
        this.state = state;
    }

    public Date getLogisticsTime() {
        return logisticsTime;
    }

    public void setLogisticsTime(Date logisticsTime) {
        this.logisticsTime = logisticsTime;
    }

    public byte[] getRemarks() {
        return remarks;
    }

    public void setRemarks(byte[] remarks) {
        this.remarks = remarks;
    }

    public String getFkUserTransactionId() {
        return fkUserTransactionId;
    }

    public void setFkUserTransactionId(String fkUserTransactionId) {
        this.fkUserTransactionId = fkUserTransactionId;
    }
}